package com.atguigu.tingshu.user.strategy.impl;

import com.atguigu.tingshu.model.user.UserPaidAlbum;
import com.atguigu.tingshu.user.mapper.UserPaidAlbumMapper;
import com.atguigu.tingshu.user.strategy.ItemTypeStrategy;
import com.atguigu.tingshu.vo.user.UserPaidRecordVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component("1001")
public class AlbumStrategy implements ItemTypeStrategy {
    @Autowired
    private UserPaidAlbumMapper userPaidAlbumMapper;
    /**
     * 购买处理项目类型为：专辑
     *
     * @param userPaidRecordVo
     */
    @Override
    public void savePaidRecord(UserPaidRecordVo userPaidRecordVo) {
        log.info("处理项目类型为：专辑");
        // 购买专辑
        UserPaidAlbum userPaidAlbum = userPaidAlbumMapper.selectOne(
                new LambdaQueryWrapper<UserPaidAlbum>()
                        .eq(UserPaidAlbum::getUserId,userPaidRecordVo.getUserId())
                        .eq(UserPaidAlbum::getAlbumId,userPaidRecordVo.getItemIdList().get(0)));
        // 判断
        if(null != userPaidAlbum){
            return;
        }
        // 创建对象保存数据
        userPaidAlbum = new UserPaidAlbum();
        // 赋值
        userPaidAlbum.setOrderNo(userPaidRecordVo.getOrderNo());
        userPaidAlbum.setUserId(userPaidRecordVo.getUserId());
        userPaidAlbum.setAlbumId(userPaidRecordVo.getItemIdList().get(0));
        //保存数据
        userPaidAlbumMapper.insert(userPaidAlbum);
    }
}
